home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / SpellCompositor / SpellRecord.java < prev    next >
Encoding:
Java Source  |  2001-06-23  |  5.2 KB  |  250 lines

  1. /*
  2.     SpellRecord
  3.         - Data-structure for the storage of spell information
  4.     
  5.     Written by Scott C. Ziegler for use with Simulcra RPG and AD&D.
  6.     
  7.     This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications.  Any use of this software for any purpose whatsoever must have explicit permission from the author of the file.  This code is part of an ongoing development process for future possible products, and so is considered private property.
  8. Do not use without permission.  Author: Scott C. Ziegler <Aslan@Narnia.net>
  9.     
  10.     vers. history:
  11.         05.31.00 - added the School property to SpellRecord (it was erroneously
  12.                     absent.)
  13.         07.08.00 - fixed syntactic bug replacing append with setText.
  14.         07.08.00 - achieved a syntactically correct version.
  15.         08.23.00 - realized a major conceptual error in design and began to refit
  16.         09.07.00 - reached a syntactically correct version.
  17.     
  18.     Work Needed:
  19.         - fix the components by string, as m is in somantic and may trigger material
  20.     
  21.     Work Completed:
  22.         - Fixed append/setText bug 
  23.         - fixed pervasive, conceptual error in DSs.
  24.         - added SpellRegister and SpellRecord members to the DSs.
  25.         
  26.  
  27.  
  28. */
  29. package Arcana;
  30.  
  31. import java.awt.*;
  32. import java.io.*;
  33. import java.util.*;
  34. import java.awt.event.*;
  35. import java.awt.Color;
  36.  
  37.  
  38. // import SpellBookTest.Sorter;
  39.  
  40. // SpellRecord
  41. //
  42. //        Data-structure for the storage of spell information
  43.  
  44. public class SpellRecord implements Sorter.Comparable, Serializable {
  45.  
  46.     int     Level;
  47.     String     Name;
  48.     String     School;
  49.     String     Range;
  50.     int     Components;
  51.     String     Duration;
  52.     String     CastingTime;
  53.     String     AreaOfEffect;
  54.     String     SavingThrow;
  55.     
  56.     SpellDescription effect;
  57.     
  58.     static final int VERBAL = 1;
  59.     static final int SOMANTIC = 2;
  60.     static final int MATERIAL = 4;
  61.     static final int VERBAL_SOMANTIC = 3;
  62.     static final int SOMANTIC_MATERIAL = 6;
  63.     static final int VERBAL_MATERIAL = 5;
  64.     static final int VERBAL_SOMANTIC_MATERIAL = 7;
  65.     
  66.     SpellRegister    register; // need to implement this though class
  67.     
  68.     public SpellRecord(int lvl, String name, String school, String range, 
  69.                     int components, String duration, String castTime, String aoe, String save) {
  70.                 
  71.         Level = lvl;
  72.         Name = name;
  73.         School = school;
  74.         Range = range;
  75.         Components = components;
  76.         Duration = duration;
  77.         CastingTime = castTime;
  78.         AreaOfEffect = aoe;
  79.         SavingThrow = save;
  80.         
  81.         register = new SpellRegister(this);
  82.         effect = new SpellDescription("Bang!\n");
  83.         }
  84.         
  85.     public SpellRecord() {
  86.         Level = 1;
  87.         Name = "Untitled";
  88.         School = "Abjuration";
  89.         Range = "0";
  90.         Components = VERBAL_SOMANTIC_MATERIAL;
  91.         Duration = "1 Round";
  92.         CastingTime = "1";
  93.         AreaOfEffect = "Caster";
  94.         SavingThrow = "Negates";
  95.         
  96.         register = new SpellRegister(this);
  97.         effect = new SpellDescription("Bang!\n");
  98.         }
  99.     
  100.     // Mutators
  101.     
  102.     public void setLevel(int lvl) {
  103.         Level = lvl;
  104.         register.setLevel(lvl);
  105.         }
  106.         
  107.     public void setName(String name) {
  108.         Name = name;
  109.         register.setName(name);
  110.         }
  111.     
  112.     public void setSchool(String school) {
  113.         School = school;
  114.         register.setSchool(school);
  115.         }
  116.     
  117.     public void setRange(String range) {
  118.         Range = range;
  119.         }
  120.         
  121.     public void setComponents(int components) {
  122.         Components = components;
  123.         register.setComponents(components);
  124.         }
  125.         
  126.     public void setComponentsByString(String str) {
  127.         Components = 0;
  128.         if (str.indexOf("V") != -1) {
  129.             Components += VERBAL;
  130.             }
  131.         if (str.indexOf("S") != -1) {
  132.             Components += SOMANTIC;
  133.             }
  134.         if (str.indexOf("M") != -1) { // Oops?! soMantic
  135.             Components += MATERIAL;
  136.             }
  137.         }
  138.     
  139.     public void setDuration(String duration) {
  140.         Duration = duration;
  141.         }
  142.         
  143.     public void setCastingTime(String castingTime) {
  144.         CastingTime = castingTime;
  145.         }
  146.         
  147.     public void setAreaOfEffect(String areaOfEffect) {
  148.         AreaOfEffect = areaOfEffect;
  149.         }
  150.         
  151.     public void setSavingThrow(String savingThrow) {
  152.         SavingThrow = savingThrow;
  153.         }
  154.         
  155.     public void setEffect(SpellDescription desc) {
  156.         effect = desc;
  157.         }
  158.     
  159.     public void setSpellRegister(SpellRegister spReg) {
  160.         register = spReg;
  161.         }
  162.     
  163.     
  164.     
  165.     // Selectors
  166.     
  167.     public int getLevel() {
  168.         return Level;
  169.         }
  170.     
  171.     public String getName() {
  172.         return Name;
  173.         }
  174.     
  175.     public String getSchool() {
  176.         return School;
  177.         }
  178.     
  179.     public String getRange() {
  180.         return Range;
  181.         }
  182.         
  183.     public int getComponents() {
  184.         return Components;
  185.         }
  186.         
  187.     public String getComponentsString() {
  188.         switch(Components) {
  189.             case VERBAL :
  190.                 return new String("V");
  191.             case SOMANTIC :
  192.                 return new String("S");
  193.             case MATERIAL :
  194.                 return new String("M");
  195.             case VERBAL_SOMANTIC :
  196.                 return new String("V,S");
  197.             case SOMANTIC_MATERIAL:
  198.                 return new String("S,M");
  199.             case VERBAL_MATERIAL :
  200.                 return new String("V,M");
  201.             case VERBAL_SOMANTIC_MATERIAL :
  202.                 return new String("V,S,M");
  203.             default :
  204.                 return new String("V");
  205.             }
  206.         }
  207.         
  208.     public String getDuration() {
  209.         return Duration;
  210.         }
  211.         
  212.     public String getCastingTime() {
  213.         return CastingTime;
  214.         }
  215.         
  216.     public String getAreaOfEffect() {
  217.         return AreaOfEffect;
  218.         }
  219.         
  220.     public String getSavingThrow() {
  221.         return SavingThrow;
  222.         }
  223.         
  224.     public SpellDescription getEffect() {
  225.         return effect;
  226.         }
  227.         
  228.     public SpellRegister getSpellRegister() {
  229.         return register;
  230.         }
  231.         
  232.     // Interface - Comparable
  233.     
  234.     public int compareTo(Object other) {
  235.         return Name.compareTo(((SpellRecord)other).getName());
  236.         }
  237.     
  238.     }
  239.     
  240.     
  241.  
  242.     
  243.  
  244.  
  245.     
  246.     
  247.  
  248.     
  249.     
  250.